import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
from neuttsair.neutts import NeuTTSAir

def downloadModel():
    device = 'npu'
    NEUTTSAIR_BACKBONE = os.getenv('NEUTTSAIR_BACKBONE', 'neuphonic/neutts-air-q4-gguf')
    NEUTTSAIR_CODEC = os.getenv('NEUTTSAIR_CODEC', 'neuphonic/neucodec')
    tts = NeuTTSAir(backbone_repo=NEUTTSAIR_BACKBONE, backbone_device=device,
                    codec_repo=NEUTTSAIR_CODEC, codec_device=device)
    if tts:
        if tts.backbone:
            tts.backbone.close()

def main():
    model_root_path = "~/.cache/huggingface/hub/"
    frr = ["models--facebook--w2v-bert-2.0","models--neuphonic--neucodec" , "models--neuphonic--neutts-air-q4-gguf"]
    while count < 5 :
        flag = True
        for fn in frr:
            filepath = os.path.join(model_root_path, fn)
            if os.path.exists(filepath) == False:
                downloadModel()
                flag = False
        if flag :
            break

        count = count +1

if __name__ == '__main__':
    main()
